import type Admin from "@/types/response/admin";
import axiosManager from "../axiosManager";
import type { DataType } from "@/types/response";
import ResUtil from "@/utils/resUtil";
let instance=axiosManager.adminAxios;
async function getAdminByPhone(phoneNum:string){
  let res=await instance.get("/admin/phone",{
    params:{
      phoneNum
    }
  });
  if(ResUtil.isSuccess(res)){
    return ResUtil.getData<Admin>(res);
  }
}
async function getAdmin(adminId:number){
 let res=await instance.get("/admin",{params:{
    adminId,
  }});
  if(ResUtil.isSuccess(res)){
    return ResUtil.getData<Admin>(res);
  }
  return null;
}
async function addAdmin(admin:Admin){
  let res=await instance.post("/admin",admin);
  return ResUtil.getData<Admin>(res);
}
async function updateAdmin(admin:Admin){
  let res=await instance.put("/admin",admin);
  return ResUtil.isSuccess(res);
}
async function getAllAdmin(){
  let res=await instance.get("/admins");
  if(ResUtil.isSuccess(res)){
    return ResUtil.getData<Admin[]>(res);
  }
}
export{
  getAdmin,
  addAdmin,
  updateAdmin,
  getAllAdmin,
  getAdminByPhone
}